package com.jymj.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jymj.entity.KeyValueEntity;
import com.jymj.entity.Renovated;
import com.jymj.entity.dto.RenovatedDto;
import com.jymj.entity.model.PointAndTypeEntity;
import com.jymj.entity.vo.StatisticalEntity;
import com.jymj.service.RenovatedService;
import com.jymj.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by ${lc} on 2021/6/16. 翻建
 */
@RestController
@RequestMapping("/renovated")
public class RenovatedController {

    @Autowired
    private RenovatedService renovatedService;

    /**
     * 统计首页信息
     * @return date yyyy-MM
     */
    @PostMapping("/getStatistical")
    public R getStatistical(String date){
        List<StatisticalEntity> statisticalEntities = renovatedService.getStatistical(date);
        return R.ok().put("data",statisticalEntities);
    }

    /**
     * 翻建列表 条件查询
     * @param renovatedDto 可分页
     * @return
     */
    @PostMapping("/queryList")
    public R queryList(@RequestBody RenovatedDto renovatedDto){
        PageHelper.startPage(renovatedDto.getPage(),renovatedDto.getLimit());
        List<Renovated> renovateds = renovatedService.queryList(renovatedDto);
        PageInfo<Renovated> renovatedPageInfo = new PageInfo<>(renovateds);
        return R.ok().put("data",renovatedPageInfo);
    }

    /**
     * 点查翻建详情  院落详情  翻建图片详情
     * @param id 翻建id
     * @return
     */
    @PostMapping("/queryInfo")
    public R queryInfo(Long id){
        RenovatedDto renovatedDto = renovatedService.queryInfo(id);
        return R.ok().put("data",renovatedDto);
    }

    /**
     * 步骤统计
     * @param renovatedDto
     * @return
     */
    @PostMapping("/getSteps")
    public R getSteps(@RequestBody RenovatedDto renovatedDto){
        KeyValueEntity keyValueEntity = renovatedService.getSteps(renovatedDto);
        return R.ok().put("data",keyValueEntity);
    }

    /**
     * 根据xy坐标查询翻建数量与具体问题点位
     *
     * @param pointAndTypeEntity
     * @return
     */
    @PostMapping("/getRenovatedByxy")
    public R getRenovatedByxy(@RequestBody PointAndTypeEntity pointAndTypeEntity) {
        List<KeyValueEntity> keyValueEntities = renovatedService.getRenovatedByxy(pointAndTypeEntity);
        return R.ok().put("data", keyValueEntities);
    }
}
